﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using ThanNhanTao.Properties;


namespace ThanNhanTao
{
    /// <summary>
    /// Interaction logic for frmCauHinhHanBHYT.xaml
    /// </summary>
    public partial class frmCauHinhHanBHYT : DXWindow
    {
        public frmCauHinhHanBHYT()
        {
            InitializeComponent();
            try
            {
                spinEditSoNgay.EditValue = Settings.Default.SoNgayHetHan;
                chkhienThiCauHinh.IsChecked = Settings.Default.HienThiCauHinhHanBHYT;
                chkhienThiDanhSachBNHetHan.IsChecked = Settings.Default.HienThiDanhSachHetHanBHYT;
            }
            catch (Exception)
            {
                DXMessageBox.Show("Thiết lập thông tin cấu hình không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void btnLuu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int soNgay = 0;
                if (!string.IsNullOrEmpty(spinEditSoNgay.Text))
                    soNgay = Convert.ToInt32(spinEditSoNgay.Text);
                Settings.Default.SoNgayHetHan = soNgay;
                Settings.Default.HienThiCauHinhHanBHYT = (chkhienThiCauHinh.IsChecked != null ? chkhienThiCauHinh.IsChecked.Value : false);
                Settings.Default.HienThiDanhSachHetHanBHYT = (chkhienThiDanhSachBNHetHan.IsChecked != null ? chkhienThiDanhSachBNHetHan.IsChecked.Value : false);
                Settings.Default.Save();
                this.Close();
            }
            catch (Exception)
            {
                DXMessageBox.Show("Lưu thông tin cấu hình không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void btnDong_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void DXWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.Escape)
                this.Close();
        }
    }
}
